﻿using HZU.ZP.Data.Interfaces.Resume;
using HZU.ZP.Data.Models;
using HZU.ZP.Data.Models.Resume;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HZU.ZP.Data.Impl.Resume
{
    public class SelfEvaluationDao:ISelfEvaluationDao
    {
        private EFCoreDbContext _context;

        public SelfEvaluationDao(EFCoreDbContext context)
        {
            _context = context;
        }

        public void AddSelfEvaluation(SelfEvaluation selfEvaluation)
        {
            _context.SelfEvaluations.Add(selfEvaluation);
            _context.SaveChanges();
        }

        public void DeleteSelfEvaluation(int id)
        {
            var selfEvaluation = _context.SelfEvaluations.FirstOrDefault(e => e.Id == id);
            _context.SelfEvaluations.Remove(selfEvaluation);
            _context.SaveChanges();
        }

        public SelfEvaluation GetSelfEvaluation(int applicantId)
        {
            return _context.SelfEvaluations.FirstOrDefault(e => e.ApplicantId == applicantId);
        }

        public void UpdateSelfEvaluation(SelfEvaluation selfEvaluation)
        {
            _context.SelfEvaluations.Update(selfEvaluation);
            _context.SaveChanges();
        }
    }
}
